Skip to content

Comments

fix: register handler directly with ViewerService when available#3068

Closed
timar wants to merge 1 commit intomasterfrom
private/timar/fixrace
Closed

fix: register handler directly with ViewerService when available#3068
timar wants to merge 1 commit intomasterfrom
private/timar/fixrace

Conversation

@timar
Copy link
Member

@timar timar commented Feb 13, 2026

When an app (e.g. richdocuments) calls registerHandler() from the @nextcloud/viewer package, the handler is stored in the global window._oca_viewer_handlers Map. These handlers are only bridged into the ViewerService (and thus into OCA.Viewer.mimetypes) by a DOMContentLoaded listener in Viewer.vue.

Since all Nextcloud scripts are loaded with the defer attribute, there is a race window between the file list rendering and DOMContentLoaded firing. If the files app finishes rendering before the bridge runs, viewerAction's enabled() check reads OCA.Viewer.mimetypes before document mimetypes have been added — the viewer action is disabled and the download action takes over, causing documents to be downloaded instead of opened in Collabora/the viewer.

Fix this by also registering the handler directly with the ViewerService when it is already initialized. Because viewer-init runs before other apps' init scripts (both are deferred, viewer registers its LoadViewer listener first), OCA.Viewer is guaranteed to exist when richdocuments' init-viewer script calls registerHandler(). Duplicate registration is harmless — ViewerService.registerHandler() already rejects handlers whose id is already known.

When an app (e.g. richdocuments) calls registerHandler() from the
@nextcloud/viewer package, the handler is stored in the global
window._oca_viewer_handlers Map. These handlers are only bridged into
the ViewerService (and thus into OCA.Viewer.mimetypes) by a
DOMContentLoaded listener in Viewer.vue.

Since all Nextcloud scripts are loaded with the defer attribute, there
is a race window between the file list rendering and DOMContentLoaded
firing. If the files app finishes rendering before the bridge runs,
viewerAction's enabled() check reads OCA.Viewer.mimetypes before
document mimetypes have been added — the viewer action is disabled
and the download action takes over, causing documents to be downloaded
instead of opened in Collabora/the viewer.

Fix this by also registering the handler directly with the
ViewerService when it is already initialized. Because viewer-init
runs before other apps' init scripts (both are deferred, viewer
registers its LoadViewer listener first), OCA.Viewer is guaranteed to
exist when richdocuments' init-viewer script calls registerHandler().
Duplicate registration is harmless — ViewerService.registerHandler()
already rejects handlers whose id is already known.

Signed-off-by: Andras Timar <andras.timar@collabora.com>
@timar
Copy link
Member Author

timar commented Feb 13, 2026

This PR did not fix the bug. :(

@timar timar closed this Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant